import regeneratorRuntime from '../../resource/libs/runtime'
import { wxApiPromise, redirectBack } from '../../common/utils'
import service from '../../common/service'

let app = getApp()

Page({
  data: {
    auth_type: ''
  },

  onLoad (options) {
    this.setData({
      auth_type: options.auth_type
    })
  },

  // 获取用户的微信资料并存储，跳转回原来的页面
  async getUserInfo ({ detail }) {
    let { encryptedData, iv } = detail
    let res = await service.postPromise('user/info', { encryptedData, iv })
    if (!res) { return }
    if (typeof res === 'number') {
      wx.showModal({
        title: '资料获取失败',
        showCancel: false
      })
      return
    }
    redirectBack()
  },

  // 打开设置，授权地理位置后跳转回原来的页面
  async openSetting () {
    let res = await wxApiPromise(wx.openSetting)
    if (res.authSetting['scope.userLocation']) {
      redirectBack()
    }
  }
})